<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            padding: 100px;
        }

        textarea {
            resize: none;
            width: 200px;
            height: 100px;
            outline: none;
        }

        ul li {
            width: 200px;
            margin-right: 50px;
            background-color: orange;
        }

        li a {
            float: right;
        }
    </style>
</head>

<body>
    <textarea name="" id=""></textarea>
    <button>发布</button>
    <button>删除</button>
    <ul></ul>

    <script>
        var button = document.querySelector('button')
        var ul = document.querySelector('ul')
        var text = document.querySelector('textarea')
   var as;
        var bu1 = button.nextElementSibling
        console.log(bu1);
        bu1.onclick = function () {
            if (ul.children.length == 0) {
                this.disabled = true
                return;
            }
            ul.removeChild(ul.children[ul.children.length - 1]);
        }
        button.onclick = function () {
            if (text.value == '') {
                alert('请输入内容')
                return;
            }
            else {

                var li = document.createElement('li');
                li.innerHTML = text.value + '<a href="javascript:;" id="a">删除</a>';
                ul.insertBefore(li, ul.children[0])
                as = document.querySelectorAll('a');
                console.log(as);
                for (var i = 0; i < as.length; i++) {
                    as[i].onclick = function () {
                        ul.removeChild(this.parentNode);
                    }
                }
            }
        }


    </script>
</body>

</html>